using System;
using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using Csla.Validation;
using BA.DAL;
using BA;
using System.Text;

namespace BlazeApps.Library.Form
{
    [Serializable()]
    public class FormQuestionDetail : Csla.BusinessBase<FormQuestionDetail>
    {
        private BlazeApps.Library.ConfigSettings Config = new BlazeApps.Library.ConfigSettings();
        private BA.DAL.DBUtility DAL = new BA.DAL.DBUtility();
        private Procedures Procs = new Procedures();

        #region Business Properties and Methods

        //declare members
        private Guid _formID = Guid.NewGuid();
        private Guid _formQuestionID = Guid.NewGuid();
        private string _question = string.Empty;
        private Guid _formControlID = Guid.NewGuid();
        private int _formControlWidth = 0;
        private int _formControlHeight = 0;
        private int _formControlRows = 0;
        private int _formControlCols = 0;
        private int _formControlLayout = 0;
        private int _formPage = 0;
        private bool _isRequired = false;
        private string _requiredText = string.Empty;
        private bool _isRegularExpressionValidatorRequired = false;
        private string _regularExpression = string.Empty;
        private string _regularExpressionValidatorText = string.Empty;
        private bool _isCompareValidatorRequired = false;
        private int _compareValidatorType = 0;
        private string _compareValidatorText = string.Empty;
        private bool _isRangeValidatorRequired = false;
        private string _rangeValidatorText = string.Empty;
        private string _rangeStart = string.Empty;
        private string _rangeEnd = string.Empty;
        private SmartDate _createDate = new SmartDate(false);
        private int _sortOrder = 0;
		private bool _isOtherOption = false;
		private string _otherOptionText = string.Empty;

        public Guid FormID
        {
            get
            {
                CanReadProperty("FormID", true);
                return _formID;
            }
            set
            {
                CanWriteProperty("FormID", true);
                if (!_formID.Equals(value))
                {
                    _formID = value;
                    PropertyHasChanged("FormID");
                }
            }
        }

        [System.ComponentModel.DataObjectField(true, true)]
        public Guid FormQuestionID
        {
            get
            {
                CanReadProperty("FormQuestionID", true);
                return _formQuestionID;
            }
        }

        public string Question
        {
            get
            {
                CanReadProperty("Question", true);
                return _question;
            }
            set
            {
                CanWriteProperty("Question", true);
                if (value == null)
                    value = string.Empty;
                if (!_question.Equals(value))
                {
                    _question = value;
                    PropertyHasChanged("Question");
                }
            }
        }

        public Guid FormControlID
        {
            get
            {
                CanReadProperty("FormControlID", true);
                return _formControlID;
            }
            set
            {
                CanWriteProperty("FormControlID", true);
                if (!_formControlID.Equals(value))
                {
                    _formControlID = value;
                    PropertyHasChanged("FormControlID");
                }
            }
        }

        public int FormControlWidth
        {
            get
            {
                CanReadProperty("FormControlWidth", true);
                return _formControlWidth;
            }
            set
            {
                CanWriteProperty("FormControlWidth", true);
                if (!_formControlWidth.Equals(value))
                {
                    _formControlWidth = value;
                    PropertyHasChanged("FormControlWidth");
                }
            }
        }

        public int FormControlHeight
        {
            get
            {
                CanReadProperty("FormControlHeight", true);
                return _formControlHeight;
            }
            set
            {
                CanWriteProperty("FormControlHeight", true);
                if (!_formControlHeight.Equals(value))
                {
                    _formControlHeight = value;
                    PropertyHasChanged("FormControlHeight");
                }
            }
        }

        public int FormControlRows
        {
            get
            {
                CanReadProperty("FormControlRows", true);
                return _formControlRows;
            }
            set
            {
                CanWriteProperty("FormControlRows", true);
                if (!_formControlRows.Equals(value))
                {
                    _formControlRows = value;
                    PropertyHasChanged("FormControlRows");
                }
            }
        }

        public int FormControlCols
        {
            get
            {
                CanReadProperty("FormControlCols", true);
                return _formControlCols;
            }
            set
            {
                CanWriteProperty("FormControlCols", true);
                if (!_formControlCols.Equals(value))
                {
                    _formControlCols = value;
                    PropertyHasChanged("FormControlCols");
                }
            }
        }

        public int FormControlLayout
        {
            get
            {
                CanReadProperty("FormControlLayout", true);
                return _formControlLayout;
            }
            set
            {
                CanWriteProperty("FormControlLayout", true);
                if (!_formControlLayout.Equals(value))
                {
                    _formControlLayout = value;
                    PropertyHasChanged("FormControlLayout");
                }
            }
        }

        public int FormPage
        {
            get
            {
                CanReadProperty("FormPage", true);
                return _formPage;
            }
            set
            {
                CanWriteProperty("FormPage", true);
                if (!_formPage.Equals(value))
                {
                    _formPage = value;
                    PropertyHasChanged("FormPage");
                }
            }
        }

        public bool IsRequired
        {
            get
            {
                CanReadProperty("IsRequired", true);
                return _isRequired;
            }
            set
            {
                CanWriteProperty("IsRequired", true);
                if (!_isRequired.Equals(value))
                {
                    _isRequired = value;
                    PropertyHasChanged("IsRequired");
                }
            }
        }

        public string RequiredText
        {
            get
            {
                CanReadProperty("RequiredText", true);
                return _requiredText;
            }
            set
            {
                CanWriteProperty("RequiredText", true);
                if (value == null)
                    value = string.Empty;
                if (!_requiredText.Equals(value))
                {
                    _requiredText = value;
                    PropertyHasChanged("RequiredText");
                }
            }
        }

        public bool IsRegularExpressionValidatorRequired
        {
            get
            {
                CanReadProperty("IsRegularExpressionValidatorRequired", true);
                return _isRegularExpressionValidatorRequired;
            }
            set
            {
                CanWriteProperty("IsRegularExpressionValidatorRequired", true);
                if (!_isRegularExpressionValidatorRequired.Equals(value))
                {
                    _isRegularExpressionValidatorRequired = value;
                    PropertyHasChanged("IsRegularExpressionValidatorRequired");
                }
            }
        }

        public string RegularExpression
        {
            get
            {
                CanReadProperty("RegularExpression", true);
                return _regularExpression;
            }
            set
            {
                CanWriteProperty("RegularExpression", true);
                if (value == null)
                    value = string.Empty;
                if (!_regularExpression.Equals(value))
                {
                    _regularExpression = value;
                    PropertyHasChanged("RegularExpression");
                }
            }
        }

        public string RegularExpressionValidatorText
        {
            get
            {
                CanReadProperty("RegularExpressionValidatorText", true);
                return _regularExpressionValidatorText;
            }
            set
            {
                CanWriteProperty("RegularExpressionValidatorText", true);
                if (value == null)
                    value = string.Empty;
                if (!_regularExpressionValidatorText.Equals(value))
                {
                    _regularExpressionValidatorText = value;
                    PropertyHasChanged("RegularExpressionValidatorText");
                }
            }
        }

        public bool IsCompareValidatorRequired
        {
            get
            {
                CanReadProperty("IsCompareValidatorRequired", true);
                return _isCompareValidatorRequired;
            }
            set
            {
                CanWriteProperty("IsCompareValidatorRequired", true);
                if (!_isCompareValidatorRequired.Equals(value))
                {
                    _isCompareValidatorRequired = value;
                    PropertyHasChanged("IsCompareValidatorRequired");
                }
            }
        }

        public int CompareValidatorType
        {
            get
            {
                CanReadProperty("CompareValidatorType", true);
                return _compareValidatorType;
            }
            set
            {
                CanWriteProperty("CompareValidatorType", true);
                if (!_compareValidatorType.Equals(value))
                {
                    _compareValidatorType = value;
                    PropertyHasChanged("CompareValidatorType");
                }
            }
        }

        public string CompareValidatorText
        {
            get
            {
                CanReadProperty("CompareValidatorText", true);
                return _compareValidatorText;
            }
            set
            {
                CanWriteProperty("CompareValidatorText", true);
                if (value == null)
                    value = string.Empty;
                if (!_compareValidatorText.Equals(value))
                {
                    _compareValidatorText = value;
                    PropertyHasChanged("CompareValidatorText");
                }
            }
        }

        public bool IsRangeValidatorRequired
        {
            get
            {
                CanReadProperty("IsRangeValidatorRequired", true);
                return _isRangeValidatorRequired;
            }
            set
            {
                CanWriteProperty("IsRangeValidatorRequired", true);
                if (!_isRangeValidatorRequired.Equals(value))
                {
                    _isRangeValidatorRequired = value;
                    PropertyHasChanged("IsRangeValidatorRequired");
                }
            }
        }

        public string RangeValidatorText
        {
            get
            {
                CanReadProperty("RangeValidatorText", true);
                return _rangeValidatorText;
            }
            set
            {
                CanWriteProperty("RangeValidatorText", true);
                if (value == null)
                    value = string.Empty;
                if (!_rangeValidatorText.Equals(value))
                {
                    _rangeValidatorText = value;
                    PropertyHasChanged("RangeValidatorText");
                }
            }
        }

        public string RangeStart
        {
            get
            {
                CanReadProperty("RangeStart", true);
                return _rangeStart;
            }
            set
            {
                CanWriteProperty("RangeStart", true);
                if (value == null)
                    value = string.Empty;
                if (!_rangeStart.Equals(value))
                {
                    _rangeStart = value;
                    PropertyHasChanged("RangeStart");
                }
            }
        }

        public string RangeEnd
        {
            get
            {
                CanReadProperty("RangeEnd", true);
                return _rangeEnd;
            }
            set
            {
                CanWriteProperty("RangeEnd", true);
                if (value == null)
                    value = string.Empty;
                if (!_rangeEnd.Equals(value))
                {
                    _rangeEnd = value;
                    PropertyHasChanged("RangeEnd");
                }
            }
        }

        public DateTime CreateDate
        {
            get
            {
                CanReadProperty("CreateDate", true);
                return _createDate.Date;
            }
        }

        public string CreateDateString
        {
            get
            {
                CanReadProperty("CreateDate", true);
                return _createDate.Text;
            }
            set
            {
                CanWriteProperty("CreateDate", true);
                if (value == null)
                    value = string.Empty;
                if (!_createDate.Equals(value))
                {
                    _createDate.Text = value;
                    PropertyHasChanged("CreateDate");
                }
            }
        }

        public int SortOrder
        {
            get
            {
                CanReadProperty("SortOrder", true);
                return _sortOrder;
            }
            set
            {
                CanWriteProperty("SortOrder", true);
                if (!_sortOrder.Equals(value))
                {
                    _sortOrder = value;
                    PropertyHasChanged("SortOrder");
                }
            }
        }

		public bool IsOtherOption
		{
			get
			{
				CanReadProperty("IsOtherOption", true);
				return _isOtherOption;
			}
			set
			{
				CanWriteProperty("IsOtherOption", true);
				if (!_isOtherOption.Equals(value))
				{
					_isOtherOption = value;
					PropertyHasChanged("IsOtherOption");
				}
			}
		}

		public string OtherOptionText
		{
			get
			{
				CanReadProperty("OtherOptionText", true);
				return _otherOptionText;
			}
			set
			{
				CanWriteProperty("OtherOptionText", true);
				if (value == null)
					value = string.Empty;
				if (!_otherOptionText.Equals(value))
				{
					_otherOptionText = value;
					PropertyHasChanged("OtherOptionText");
				}
			}
		}

        protected override object GetIdValue()
        {
            return _formQuestionID;
        }

        #endregion //Business Properties and Methods

        #region Validation Rules
        private void AddCustomRules()
        {
            //add custom/non-generated rules here...
        }

        private void AddCommonRules()
        {
            //
            // Question
            //
            ValidationRules.AddRule(CommonRules.StringRequired, "Question");
        }

        protected override void AddBusinessRules()
        {
            AddCommonRules();
            AddCustomRules();
        }
        #endregion //Validation Rules

        #region Authorization Rules
        protected override void AddAuthorizationRules()
        {
            //TODO: Define authorization rules in FormQuestionDetail
            //AuthorizationRules.AllowRead("FormID", "FormQuestionDetailReadGroup");
            //AuthorizationRules.AllowRead("FormQuestionID", "FormQuestionDetailReadGroup");
            //AuthorizationRules.AllowRead("Question", "FormQuestionDetailReadGroup");
            //AuthorizationRules.AllowRead("FormControlID", "FormQuestionDetailReadGroup");
            //AuthorizationRules.AllowRead("FormControlWidth", "FormQuestionDetailReadGroup");
            //AuthorizationRules.AllowRead("FormControlHeight", "FormQuestionDetailReadGroup");
            //AuthorizationRules.AllowRead("FormControlRows", "FormQuestionDetailReadGroup");
            //AuthorizationRules.AllowRead("FormControlCols", "FormQuestionDetailReadGroup");
            //AuthorizationRules.AllowRead("FormPage", "FormQuestionDetailReadGroup");
            //AuthorizationRules.AllowRead("IsRequired", "FormQuestionDetailReadGroup");
            //AuthorizationRules.AllowRead("RequiredText", "FormQuestionDetailReadGroup");

            //AuthorizationRules.AllowWrite("Question", "FormQuestionDetailWriteGroup");
            //AuthorizationRules.AllowWrite("FormControlWidth", "FormQuestionDetailWriteGroup");
            //AuthorizationRules.AllowWrite("FormControlHeight", "FormQuestionDetailWriteGroup");
            //AuthorizationRules.AllowWrite("FormControlRows", "FormQuestionDetailWriteGroup");
            //AuthorizationRules.AllowWrite("FormControlCols", "FormQuestionDetailWriteGroup");
            //AuthorizationRules.AllowWrite("FormPage", "FormQuestionDetailWriteGroup");
            //AuthorizationRules.AllowWrite("IsRequired", "FormQuestionDetailWriteGroup");
            //AuthorizationRules.AllowWrite("RequiredText", "FormQuestionDetailWriteGroup");
        }


        public static bool CanGetObject()
        {
            //TODO: Define CanGetObject permission in FormQuestionDetail
            return true;
            //if (Csla.ApplicationContext.User.IsInRole("FormQuestionDetailViewGroup"))
            //	return true;
            //return false;
        }

        public static bool CanAddObject()
        {
            //TODO: Define CanAddObject permission in FormQuestionDetail
            return true;
            //if (Csla.ApplicationContext.User.IsInRole("FormQuestionDetailAddGroup"))
            //	return true;
            //return false;
        }

        public static bool CanEditObject()
        {
            //TODO: Define CanEditObject permission in FormQuestionDetail
            return true;
            //if (Csla.ApplicationContext.User.IsInRole("FormQuestionDetailEditGroup"))
            //	return true;
            //return false;
        }

        public static bool CanDeleteObject()
        {
            //TODO: Define CanDeleteObject permission in FormQuestionDetail
            return true;
            //if (Csla.ApplicationContext.User.IsInRole("FormQuestionDetailDeleteGroup"))
            //	return true;
            //return false;
        }
        #endregion //Authorization Rules

        #region Factory Methods
        private FormQuestionDetail()
        { /* require use of factory method */
        }

        public static FormQuestionDetail NewFormQuestionDetail()
        {
            if (!CanAddObject())
                throw new System.Security.SecurityException("User not authorized to add a FormQuestionDetail");
            return DataPortal.Create<FormQuestionDetail>();
        }

        public static FormQuestionDetail GetFormQuestionDetail(Guid formQuestionID)
        {
            if (!CanGetObject())
                throw new System.Security.SecurityException("User not authorized to view a FormQuestionDetail");
            return DataPortal.Fetch<FormQuestionDetail>(new Criteria(formQuestionID));
        }

        public static void DeleteFormQuestionDetail(Guid formQuestionID)
        {
            if (!CanDeleteObject())
                throw new System.Security.SecurityException("User not authorized to remove a FormQuestionDetail");
            DataPortal.Delete(new Criteria(formQuestionID));
        }

        public override FormQuestionDetail Save()
        {
            if (IsDeleted && !CanDeleteObject())
                throw new System.Security.SecurityException("User not authorized to remove a FormQuestionDetail");
            else if (IsNew && !CanAddObject())
                throw new System.Security.SecurityException("User not authorized to add a FormQuestionDetail");
            else if (!CanEditObject())
                throw new System.Security.SecurityException("User not authorized to update a FormQuestionDetail");

            return base.Save();
        }

        #endregion //Factory Methods

        #region Data Access

        #region Criteria

        [Serializable()]
        private class Criteria
        {
            public Guid FormQuestionID;

            public Criteria(Guid formQuestionID)
            {
                this.FormQuestionID = formQuestionID;
            }
        }

        #endregion //Criteria

        #region Data Access - Create
        [RunLocal]
        protected override void DataPortal_Create()
        {
            ValidationRules.CheckRules();
        }

        #endregion //Data Access - Create

        #region Data Access - Fetch
        private void DataPortal_Fetch(Criteria criteria)
        {
            ExecuteFetch(criteria);
        }

        private void ExecuteFetch(Criteria criteria)
        {

            DAL.CreateDBObjects(Config.ConnectionString, Config.Provider);

            DAL.AddParameter("@FormQuestionID", criteria.FormQuestionID);

            using (SafeDataReader dr = new SafeDataReader(DAL.ExecuteReader(Procs.GetFormQuestionByQuestionID.ToString().Trim(), CommandType.Text, ConnectionState.Open)))
            {
                FetchObject(dr);
                ValidationRules.CheckRules();

                //load child object(s)
                FetchChildren(dr);
            }
        }

        private void FetchObject(SafeDataReader dr)
        {
            dr.Read();
            _formID = dr.GetGuid("FormID");
            _formQuestionID = dr.GetGuid("FormQuestionID");
            _question = dr.GetString("Question");
            _formControlID = dr.GetGuid("FormControlID");
            _formControlWidth = dr.GetInt32("FormControlWidth");
            _formControlHeight = dr.GetInt32("FormControlHeight");
            _formControlRows = dr.GetInt32("FormControlRows");
            _formControlCols = dr.GetInt32("FormControlCols");
            _formControlLayout = dr.GetInt32("FormControlLayout");
            _formPage = dr.GetInt32("FormPage");
            _isRequired = dr.GetBoolean("IsRequired");
            _requiredText = dr.GetString("RequiredText");
            _isRegularExpressionValidatorRequired = dr.GetBoolean("IsRegularExpressionValidatorRequired");
            _regularExpression = dr.GetString("RegularExpression");
            _regularExpressionValidatorText = dr.GetString("RegularExpressionValidatorText");
            _isCompareValidatorRequired = dr.GetBoolean("IsCompareValidatorRequired");
            _compareValidatorType = dr.GetInt32("CompareValidatorType");
            _compareValidatorText = dr.GetString("CompareValidatorText");
            _isRangeValidatorRequired = dr.GetBoolean("IsRangeValidatorRequired");
            _rangeValidatorText = dr.GetString("RangeValidatorText");
            _rangeStart = dr.GetString("RangeStart");
            _rangeEnd = dr.GetString("RangeEnd");
            _createDate = dr.GetSmartDate("CreateDate", _createDate.EmptyIsMin);
            _sortOrder = dr.GetInt32("SortOrder");
			_sortOrder = dr.GetInt32("SortOrder");
			_isOtherOption = dr.GetBoolean("IsOtherOption");
			_otherOptionText = dr.GetString("OtherOptionText");
        }

        private void FetchChildren(SafeDataReader dr)
        {
        }
        #endregion //Data Access - Fetch

        #region Data Access - Insert

        protected override void DataPortal_Insert()
        {
            ExecuteInsert();
        }

        private void ExecuteInsert()
        {
            DAL.CreateDBObjects(Config.ConnectionString, Config.Provider);

            AddInsertParameters(ref DAL);

            DAL.ExecuteNonQuery(Procs.InsertFormQuestion.ToString().Trim(), CommandType.Text, ConnectionState.Open);
        }

        private void AddInsertParameters(ref BA.DAL.DBUtility DAL)
        {
            DAL.AddParameter("@FormID", _formID);
            DAL.AddParameter("@FormQuestionID", _formQuestionID);
            DAL.AddParameter("@FormControlID", _formControlID);
            DAL.AddParameter("@Question", _question);
            if (_formControlWidth != 0)
                DAL.AddParameter("@FormControlWidth", _formControlWidth);
            else
                DAL.AddParameter("@FormControlWidth", DBNull.Value);
            if (_formControlHeight != 0)
                DAL.AddParameter("@FormControlHeight", _formControlHeight);
            else
                DAL.AddParameter("@FormControlHeight", DBNull.Value);
            if (_formControlRows != 0)
                DAL.AddParameter("@FormControlRows", _formControlRows);
            else
                DAL.AddParameter("@FormControlRows", DBNull.Value);
            if (_formControlCols != 0)
                DAL.AddParameter("@FormControlCols", _formControlCols);
            else
                DAL.AddParameter("@FormControlCols", DBNull.Value);
            if (_formControlLayout != 0)
                DAL.AddParameter("@FormControlLayout", _formControlLayout);
            else
                DAL.AddParameter("@FormControlLayout", DBNull.Value);
            DAL.AddParameter("@FormPage", _formPage);
            if (_isRequired != false)
                DAL.AddParameter("@IsRequired", _isRequired);
            else
                DAL.AddParameter("@IsRequired", DBNull.Value);
            if (_requiredText != string.Empty)
                DAL.AddParameter("@RequiredText", _requiredText);
            else
                DAL.AddParameter("@RequiredText", DBNull.Value);
            if (_isRegularExpressionValidatorRequired != false)
                DAL.AddParameter("@IsRegularExpressionValidatorRequired", _isRegularExpressionValidatorRequired);
            else
                DAL.AddParameter("@IsRegularExpressionValidatorRequired", DBNull.Value);
            if (_regularExpression != string.Empty)
                DAL.AddParameter("@RegularExpression", _regularExpression);
            else
                DAL.AddParameter("@RegularExpression", DBNull.Value);
            if (_regularExpressionValidatorText != string.Empty)
                DAL.AddParameter("@RegularExpressionValidatorText", _regularExpressionValidatorText);
            else
                DAL.AddParameter("@RegularExpressionValidatorText", DBNull.Value);
            if (_isCompareValidatorRequired != false)
                DAL.AddParameter("@IsCompareValidatorRequired", _isCompareValidatorRequired);
            else
                DAL.AddParameter("@IsCompareValidatorRequired", DBNull.Value);
            if (_compareValidatorType != 0)
                DAL.AddParameter("@CompareValidatorType", _compareValidatorType);
            else
                DAL.AddParameter("@CompareValidatorType", DBNull.Value);
            if (_compareValidatorText != string.Empty)
                DAL.AddParameter("@CompareValidatorText", _compareValidatorText);
            else
                DAL.AddParameter("@CompareValidatorText", DBNull.Value);
            if (_isRangeValidatorRequired != false)
                DAL.AddParameter("@IsRangeValidatorRequired", _isRangeValidatorRequired);
            else
                DAL.AddParameter("@IsRangeValidatorRequired", DBNull.Value);
            if (_rangeValidatorText != string.Empty)
                DAL.AddParameter("@RangeValidatorText", _rangeValidatorText);
            else
                DAL.AddParameter("@RangeValidatorText", DBNull.Value);
            if (_rangeStart != string.Empty)
                DAL.AddParameter("@RangeStart", _rangeStart);
            else
                DAL.AddParameter("@RangeStart", DBNull.Value);
            if (_rangeEnd != string.Empty)
                DAL.AddParameter("@RangeEnd", _rangeEnd);
            else
                DAL.AddParameter("@RangeEnd", DBNull.Value);
            DAL.AddParameter("@CreateDate", _createDate.DBValue);
			if (_isOtherOption != false)
				DAL.AddParameter("@IsOtherOption", _isOtherOption);
			else
				DAL.AddParameter("@IsOtherOption", DBNull.Value);
			if (_otherOptionText != string.Empty)
				DAL.AddParameter("@OtherOptionText", _otherOptionText);
			else
				DAL.AddParameter("@OtherOptionText", DBNull.Value);
        }
        #endregion //Data Access - Insert

        #region Data Access - Update

        protected override void DataPortal_Update()
        {
            if (base.IsDirty)
            {
                ExecuteUpdate();
            }
        }

        private void ExecuteUpdate()
        {
            DAL.CreateDBObjects(Config.ConnectionString, Config.Provider);

            AddUpdateParameters(ref DAL);

            DAL.ExecuteNonQuery(Procs.UpdateFormQuestion.ToString().Trim(), CommandType.Text, ConnectionState.Open);
        }

        private void AddUpdateParameters(ref BA.DAL.DBUtility DAL)
        {
            DAL.AddParameter("@FormID", _formID);
            DAL.AddParameter("@FormQuestionID", _formQuestionID);
            DAL.AddParameter("@Question", _question);
            DAL.AddParameter("@FormControlID", _formControlID);
            if (_formControlWidth != 0)
                DAL.AddParameter("@FormControlWidth", _formControlWidth);
            else
                DAL.AddParameter("@FormControlWidth", DBNull.Value);
            if (_formControlHeight != 0)
                DAL.AddParameter("@FormControlHeight", _formControlHeight);
            else
                DAL.AddParameter("@FormControlHeight", DBNull.Value);
            if (_formControlRows != 0)
                DAL.AddParameter("@FormControlRows", _formControlRows);
            else
                DAL.AddParameter("@FormControlRows", DBNull.Value);
            if (_formControlCols != 0)
                DAL.AddParameter("@FormControlCols", _formControlCols);
            else
                DAL.AddParameter("@FormControlCols", DBNull.Value);
            if (_formControlLayout != 0)
                DAL.AddParameter("@FormControlLayout", _formControlLayout);
            else
                DAL.AddParameter("@FormControlLayout", DBNull.Value);
            DAL.AddParameter("@FormPage", _formPage);
            if (_isRequired != false)
                DAL.AddParameter("@IsRequired", _isRequired);
            else
                DAL.AddParameter("@IsRequired", DBNull.Value);
            if (_requiredText != string.Empty)
                DAL.AddParameter("@RequiredText", _requiredText);
            else
                DAL.AddParameter("@RequiredText", DBNull.Value);
            if (_isRegularExpressionValidatorRequired != false)
                DAL.AddParameter("@IsRegularExpressionValidatorRequired", _isRegularExpressionValidatorRequired);
            else
                DAL.AddParameter("@IsRegularExpressionValidatorRequired", DBNull.Value);
            if (_regularExpression != string.Empty)
                DAL.AddParameter("@RegularExpression", _regularExpression);
            else
                DAL.AddParameter("@RegularExpression", DBNull.Value);
            if (_regularExpressionValidatorText != string.Empty)
                DAL.AddParameter("@RegularExpressionValidatorText", _regularExpressionValidatorText);
            else
                DAL.AddParameter("@RegularExpressionValidatorText", DBNull.Value);
            if (_isCompareValidatorRequired != false)
                DAL.AddParameter("@IsCompareValidatorRequired", _isCompareValidatorRequired);
            else
                DAL.AddParameter("@IsCompareValidatorRequired", DBNull.Value);
            if (_compareValidatorType != 0)
                DAL.AddParameter("@CompareValidatorType", _compareValidatorType);
            else
                DAL.AddParameter("@CompareValidatorType", DBNull.Value);
            if (_compareValidatorText != string.Empty)
                DAL.AddParameter("@CompareValidatorText", _compareValidatorText);
            else
                DAL.AddParameter("@CompareValidatorText", DBNull.Value);
            if (_isRangeValidatorRequired != false)
                DAL.AddParameter("@IsRangeValidatorRequired", _isRangeValidatorRequired);
            else
                DAL.AddParameter("@IsRangeValidatorRequired", DBNull.Value);
            if (_rangeValidatorText != string.Empty)
                DAL.AddParameter("@RangeValidatorText", _rangeValidatorText);
            else
                DAL.AddParameter("@RangeValidatorText", DBNull.Value);
            if (_rangeStart != string.Empty)
                DAL.AddParameter("@RangeStart", _rangeStart);
            else
                DAL.AddParameter("@RangeStart", DBNull.Value);
            if (_rangeEnd != string.Empty)
                DAL.AddParameter("@RangeEnd", _rangeEnd);
            else
                DAL.AddParameter("@RangeEnd", DBNull.Value);
            DAL.AddParameter("@SortOrder", _sortOrder);
			if (_isOtherOption != false)
				DAL.AddParameter("@IsOtherOption", _isOtherOption);
			else
				DAL.AddParameter("@IsOtherOption", DBNull.Value);
			if (_otherOptionText != string.Empty)
				DAL.AddParameter("@OtherOptionText", _otherOptionText);
			else
				DAL.AddParameter("@OtherOptionText", DBNull.Value);
        }

        private void UpdateChildren(SqlConnection cn)
        {
        }
        #endregion //Data Access - Update

        #region Data Access - Delete
        protected override void DataPortal_DeleteSelf()
        {
            DataPortal_Delete(new Criteria(_formQuestionID));
        }

        private void DataPortal_Delete(Criteria criteria)
        {
            ExecuteDelete(criteria);
        }

        private void ExecuteDelete(Criteria criteria)
        {
            DAL.CreateDBObjects(Config.ConnectionString, Config.Provider);

            AddDeleteParameters(ref DAL, criteria);

            DAL.ExecuteNonQuery(Procs.DeleteFormQuestion.ToString().Trim(), CommandType.Text, ConnectionState.Open);
        }

        private void AddDeleteParameters(ref BA.DAL.DBUtility DAL, Criteria criteria)
        {
            DAL.AddParameter("@FormQuestionID", DbType.Guid, criteria.FormQuestionID);
        }

        #endregion //Data Access - Delete
        #endregion //Data Access
    }
}
